<?php
session_start();

// 设置用户名和密码
define('USERNAME', 'admin');
define('PASSWORD', '123456');

if (isset($_POST['username']) && isset($_POST['password'])) {
    if ($_POST['username'] === USERNAME && $_POST['password'] === PASSWORD) {
        $_SESSION['authenticated'] = true;
        header('Location: index.php'); // 登录成功后重定向到管理页面
        exit();
    } else {
        $error = '用户名或密码错误。';
    }
}

// 如果已经登录，直接重定向到管理页面
if (isset($_SESSION['authenticated']) && $_SESSION['authenticated']) {
    header('Location: index.php');
    exit();
}
?>

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>管理员登录</title>
<link rel="shortcut icon" href="http://tc.gobghui.icu/uploads/66aefd85f0edc.png">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/mdui.min.css">
</head>
<body class="mdui-theme-primary-blue mdui-theme-accent-blue">
    <div class="mdui-container">
        <h1>管理员登录</h1>
        <?php if (isset($error)): ?>
            <div class="mdui-alert mdui-alert-danger"><?php echo htmlspecialchars($error); ?></div>
        <?php endif; ?>
        <form method="POST">
            <div class="mdui-textfield">
                <label class="mdui-textfield-label">用户名</label>
                <input class="mdui-textfield-input" type="text" name="username" required>
            </div>
            <div class="mdui-textfield">
                <label class="mdui-textfield-label">密码</label>
                <input class="mdui-textfield-input" type="password" name="password" required>
            </div>
            <button class="mdui-btn mdui-btn-raised" type="submit">登录</button>
        </form>
    </div>
</body>
</html>
